<?php
use yii\helpers\Html;
use common\components\helpers\Fun;
use common\components\extenders\MenuManage;
use doumiaoduo\layer\LayerAsset;
?>
    <div class="docs-main">
    <table id="tablesaw" class="tablesaw table yx-table1 yx-table5 table-striped with-check"  >
    <tr class="yx-bgd2f6ec">
        <td>课程名称</td>
        <td>学员</td>
        <td>上课日期</td>
        <td>上课时间</td>
        <td>课次</td>
        <td>状态</td>
        <td>操作</td>

    </tr>
    <?php foreach ($class_lesson_arr as $i => $v):?>
        <tr>
            <td><?=\yii\helpers\Html::encode($v['title'])?></td>
            <td><?=\yii\helpers\Html::encode($v['name'])?></td>
            <td><?=$v['class_date']?></td>
            <td><?=$v['time']?></td>
            <td><?=\yii\helpers\Html::encode($v['lesson'])?></td>
            <td><?php
                $nowDate = date('Y-m-d',time());

                if($v['status'] == 0 &&  $nowDate > $v['class_date']) {
                      echo '旷课';
                } elseif($v['status'] == 2){
                      echo '请假';
                } elseif($v['status'] == 3){
                     echo '退课';
                 }elseif($v['status'] == 1){
                     echo '已打卡';
                 }else{
                      echo '未打卡';
                  }
                ?></td>
            <td>
                <?php
                if($v['status'] == 0 && $nowDate == $v['class_date']){?>
                    <?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('artclassmanage','signin',false,['class' => 'btn yx-radius2 yx-d-card yx-bg94d5a2','data'=>['id'=>$v['id']]]);?>
                <?php }else{?>
                    <span style="color:#ccc">打卡</span>
                <?php };?>
            </td>
        </tr>
    <?php endforeach; ?>
</table>
    </div>
<div id="return" style="display: none"></div>
<?php
LayerAsset::register($this);
$js=<<<JS
    layer.config({
        extend: ['skin/customskin/style.css']//加载您的扩展样式
    });
    $(document).on('click','.btn',function(){
        var _this = $(this);
        var url = _this.data('url');
        var name = _this.parents('tr').find('td').eq(1).html();
        var day = _this.parents('tr').find('td').eq(2).html();
        var status = _this.parents('tr').find('td').eq(5);
         layer.confirm("确定给"+name+"打"+day+"的卡么？", {
            title: '打卡',
            area: ['440px', '270px'],
            skin: 'layui-confirm-customskin',
            shift:1,
            id:'layer-iframe',
            btn: ['确定','取消'],
            yes: function(index, layero){
                 $.ajax({
                    url:url,
                    type:'get',
                    dataType:'json',
                    _csrf:yii.getCsrfToken(),
                    success:function(data){
                        if(data.status == 1){
                            layer.msg("打卡成功！",{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
                            $('#return').html(data.str);
                            _this.remove();
                            status.html('已打卡');
                        }else if(data.status == 2){
                           layer.msg("请在上课当天打卡！",{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
                            return false;
                        }else{
                            layer.msg("打卡失败！",{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
                            return false;
                        }
                    }

                });
              layer.close(index);
            }
         });
        return false;
    });

JS;
\Yii::$app->view->registerJs($js);
?>